package com.qdy.pay.mode;

import com.qdy.pay.common.RandomStringGenerator;
import com.qdy.pay.common.Signature;
import com.qdy.pay.common.WeixinConfigure;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * 微信小程序提交的支付订单
 * 
 * @author zuoliangzhu
 *
 */
public class WeiXinPayData {
	private String appid;// 小程序ID	
	private String mch_id;// 商户号
	private String nonce_str;// 随机字符串
	private String sign_type="MD5";//签名类型
	private String sign;// 签名
	private String body;// 商品描述
	private String out_trade_no;// 商户订单号
	private int total_fee;// 标价金额 ,单位为分
	private String spbill_create_ip;// 终端IP
	private String notify_url;// 通知地址
	private String trade_type="JSAPI";// 交易类型
	private String openid;//用户标识


	public  WeiXinPayData(){
		initObject();
	}
	/**
	 *
	 * 微信统一订单对象
	 * @param out_trade_no 商户订单号
	 * @param body 商品描述
	 * @param total_fee   标价金额 ,单位为分
	 * @param openid 用户标识
	 * @param spbill_create_ip 终端IP
	 */
	public  WeiXinPayData(String out_trade_no,String body,int total_fee,String openid,String spbill_create_ip){
		  initObject();
		  this.nonce_str= RandomStringGenerator.getRandomStringByLength(32);
		  this.total_fee=total_fee;
		  this.body=body;
		  this.spbill_create_ip=spbill_create_ip;
		  this.openid=openid;
		  this.out_trade_no=out_trade_no;
	}
	private  void initObject(){

		this.appid=WeixinConfigure.getAppID();
		this.mch_id=WeixinConfigure.getMch_id();
		this.nonce_str= RandomStringGenerator.getRandomStringByLength(32);
		this.notify_url=WeixinConfigure.getNotify_url();

	}
	public String getSign_type() {
		return sign_type;
	}

	public void setSign_type(String sign_type) {
		this.sign_type = sign_type;
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getMch_id() {
		return mch_id;
	}

	public void setMch_id(String mch_id) {
		this.mch_id = mch_id;
	}

	public String getNonce_str() {
		return nonce_str;
	}

	public void setNonce_str(String nonce_str) {
		this.nonce_str = nonce_str;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public String getOut_trade_no() {
		return out_trade_no;
	}

	public void setOut_trade_no(String out_trade_no) {
		this.out_trade_no = out_trade_no;
	}

	public int getTotal_fee() {
		return total_fee;
	}

	public void setTotal_fee(int total_fee) {
		this.total_fee = total_fee;
	}

	public String getSpbill_create_ip() {
		return spbill_create_ip;
	}

	public void setSpbill_create_ip(String spbill_create_ip) {
		this.spbill_create_ip = spbill_create_ip;
	}

	public String getNotify_url() {
		return notify_url;
	}

	public void setNotify_url(String notify_url) {
		this.notify_url = notify_url;
	}

	public String getTrade_type() {
		return trade_type;
	}

	public void setTrade_type(String trade_type) {
		this.trade_type = trade_type;
	}

	public Map<String,Object> toMap(){
		Map<String,Object> map = new HashMap<String, Object>();
		Field[] fields = this.getClass().getDeclaredFields();
		for (Field field : fields) {
			Object obj;
			try {
				obj = field.get(this);
				if(obj!=null){
					map.put(field.getName(), obj);
				}
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return map;
	}
}
